package com.jyb.qiyefuwu.uitls;

import android.content.Context;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jyb.qiyefuwu.R;
import com.swgk.core.customview.InputFilterUtils;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.util.MToast;

public class DialogHelper {

    /**
     * @param context               上下文
     * @param dialogTextReturnValue 结果回调
     * @param title                 标题
     * @param showstart             是否必填
     * @param inputhint             提示文字
     * @param textsize              最大文字限制，小于0不限制
     */
    public static void showDialog(Context context, String title, boolean showstart, String inputhint, int textsize, boolean showTextsize, DialogTextReturnValue dialogTextReturnValue) {
        View view = View.inflate(context, R.layout.dialog_closeorder, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvRedStart = view.findViewById(R.id.tv_red_start);
        EditText eidInputdata = view.findViewById(R.id.edi_input);
        TextView tv_textsize = view.findViewById(R.id.tv_textsize);
        tv_textsize.setVisibility(showTextsize ? View.VISIBLE : View.GONE);
        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
        if (!TextUtils.isEmpty(inputhint)) {
            eidInputdata.setHint(inputhint);
        }
        tvRedStart.setVisibility(showstart ? View.VISIBLE : View.GONE);

        tv_textsize.setText("0/" + textsize);
        if (textsize > 0) {
            EditTextUtils.setEditTextFlag(eidInputdata, tv_textsize, textsize);
        }

        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);

        tvLogoutConfirm.setOnClickListener(v -> {
            if (!TextUtils.isEmpty(eidInputdata.getText().toString().trim())) {
                dialogTextReturnValue.returnvalue(eidInputdata.getText().toString().trim().replace(" ", ""), roundCornerDialog);

            } else {
                if (showstart) {
                    MToast.showLongToast(context, inputhint);
                } else {
                    dialogTextReturnValue.returnvalue(eidInputdata.getText().toString().trim().replace(" ", ""), roundCornerDialog);
                }
            }
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());

    }


    /**
     * 文字提示Dialog
     *
     * @param context               上下文
     * @param title                 标题
     * @param contentText           提示文字
     * @param CancelString          取消按钮文字
     * @param confirmString         确定文字
     * @param dialogTextReturnValue 点击确定回调
     */
    public static void showDialog(Context context, String title, String contentText, String CancelString, String confirmString, DialogFunction dialogTextReturnValue) {
        View view = View.inflate(context, R.layout.dialog_showtexttip, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);
        TextView tvContent = view.findViewById(R.id.tv_content);
        View view_lin = view.findViewById(R.id.view_lin);

        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
            tvTitle.setVisibility(View.VISIBLE);
        }else{
            tvTitle.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(contentText)) {
            tvContent.setText(contentText);
        }
        if (!TextUtils.isEmpty(CancelString)) {
            tvLogoutCancel.setVisibility(View.VISIBLE);
            view_lin.setVisibility(View.VISIBLE);
            tvLogoutCancel.setText(CancelString);
        } else {
            tvLogoutCancel.setVisibility(View.GONE);
            view_lin.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(confirmString)) {
            tvLogoutConfirm.setText(confirmString);
        }
        tvLogoutConfirm.setOnClickListener(v -> {
            roundCornerDialog.dismiss();
            dialogTextReturnValue.normalRoundDialog();
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());

    }


    /**
     * @param context               上下文
     * @param title                 标题
     * @param redtext               红色提醒文字
     * @param contentText           中间提示内容
     * @param blackboldtext         加粗提示文字
     * @param cancelString          取消按钮文字 若为空则隐藏取消
     * @param confirmString         确定按钮文字
     * @param dialogTextReturnValue 点击确定回调
     */
    public static void showDialog(Context context, String title, String redtext, String contentText, String blackboldtext, String cancelString, String confirmString, DialogFunction dialogTextReturnValue) {
        View view = View.inflate(context, R.layout.dialog_ordertip, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);
        TextView tvContent = view.findViewById(R.id.tv_content);
        TextView tv_redtext = view.findViewById(R.id.tv_redtext);
        TextView tv_blackboldtext = view.findViewById(R.id.tv_blackboldtext);
        View view_lin = view.findViewById(R.id.view_lin);

        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }

        if (!TextUtils.isEmpty(redtext)) {
            tv_redtext.setText(redtext);
        }

        if (!TextUtils.isEmpty(contentText)) {
            tvContent.setText(contentText);
            tvContent.setVisibility(View.VISIBLE);
        }else{
            tvContent.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(blackboldtext)) {
            tv_blackboldtext.setText(blackboldtext);
        }

        if (!TextUtils.isEmpty(cancelString)) {
            tvLogoutCancel.setText(cancelString);
            tvLogoutCancel.setVisibility(View.VISIBLE);
            view_lin.setVisibility(View.VISIBLE);
        } else {
            tvLogoutCancel.setVisibility(View.GONE);
            view_lin.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(confirmString)) {
            tvLogoutConfirm.setText(confirmString);
        }
        tvLogoutConfirm.setOnClickListener(v -> {
            dialogTextReturnValue.normalRoundDialog();
            roundCornerDialog.dismiss();
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());

    }


    /**
     * @param context               上下文
     * @param title                 标题
     * @param bigtext               大的黑色文字
     * @param contentText           中间提示内容
     * @param cancelString          取消按钮文字 若为空则隐藏取消
     * @param confirmString         确定按钮文字
     * @param dialogTextReturnValue 点击确定回调
     */
    public static void showDialog(Context context, String title, String bigtext, String contentText, String cancelString, String confirmString, DialogFunction dialogTextReturnValue) {
        View view = View.inflate(context, R.layout.dialog_dontapprove, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);
        TextView tvContent = view.findViewById(R.id.tv_content);
        TextView tv_redtext = view.findViewById(R.id.tv_bigtext);

        View view_lin = view.findViewById(R.id.view_lin);

        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }

        if (!TextUtils.isEmpty(bigtext)) {
            tv_redtext.setText(bigtext);
        }

        if (!TextUtils.isEmpty(contentText)) {
            tvContent.setText(contentText);
        }

        if (!TextUtils.isEmpty(cancelString)) {
            tvLogoutCancel.setText(cancelString);
            tvLogoutCancel.setVisibility(View.VISIBLE);
            view_lin.setVisibility(View.VISIBLE);
        } else {
            tvLogoutCancel.setVisibility(View.GONE);
            view_lin.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(confirmString)) {
            tvLogoutConfirm.setText(confirmString);
        }
        tvLogoutConfirm.setOnClickListener(v -> {
            dialogTextReturnValue.normalRoundDialog();
            roundCornerDialog.dismiss();
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());

    }

    /**
     *确认完成订单弹窗
     */
    public static void showDialog(Context context,DialogFunction dialogTextReturnValue) {
        View view = View.inflate(context, R.layout.dialog_cofimordercomplete, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);


        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);



        tvLogoutConfirm.setOnClickListener(v -> {
            dialogTextReturnValue.normalRoundDialog();
            roundCornerDialog.dismiss();
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());

    }
}
